// 导入消息组件和类型
import { install } from '../helpers';
import Message from './Message.vue';
import * as Types from './types';
import messageManager, { setGlobalApp } from './messageManager'; // 导入setGlobalApp函数
import { App } from 'vue';

// 组件列表
const TuiMessageComponents = {
  'tui-message': Message
};

// 安装函数
const messageInstall = (app: App) => {
  // 设置全局Vue应用实例到messageManager中
  setGlobalApp(app);
  // 安装组件
  install(app, TuiMessageComponents);

  // 将message方法挂载到app实例上
  app.config.globalProperties.$message = messageManager;

  // 同时也挂载到window上，方便在非Vue组件中使用
  (window as any).$message = messageManager;
};

// 导出Message对象，确保它包含success, warning, info, error这些方法
export const message = messageManager;

export {
  messageInstall,
  TuiMessageComponents,
  Types,
};

export default {
  messageInstall,
  ...TuiMessageComponents,
  message: messageManager
};

// 导出类型
export type { TuiMessageProps, TuiMessageType, TuiMessagePlacement, TuiMessageInstance, TuiMessage } from './types';